package com.pz.cloud.framework.glory.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.pz.cloud.framework.business.pzStudent.entity.PzStudentGpa;
import com.pz.cloud.framework.business.pzStudent.service.IPzStudentGpaService;
import com.pz.cloud.framework.business.workflow.annotation.AssembleDealFlag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.BaseController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;


@RequestMapping("gpa")
@RestController
@Api(tags = "学生成绩")
@Slf4j
public class GpaController extends BaseController<PzStudentGpa, IPzStudentGpaService> {
    /**
     * 分页列表查询
     */
    @AutoLog(value = "学生成绩-列表查询")
    @ApiOperation(value = "学生成绩-列表查询", notes = "学生成绩-列表查询")
    @GetMapping(value = "/list")
    @AssembleDealFlag
    public Result<List<PzStudentGpa>> list(@NotNull String xh, String xn) {
        Result<List<PzStudentGpa>> result = new Result<>();
        if (StringUtils.isNotBlank(xn)) {
            result.setResult(Optional.ofNullable(service.findByStdNoAndPeriod(xh, xn)).map(Arrays::asList)
                    .orElse(new ArrayList<>()));
        }
        else {
            result.setResult(service.findByStdNo(xh));
        }
        result.setSuccess(true);
        return result;
    }

}
